import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;

import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;

import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

/******************************************************************************
 * <p>
 * File: GameSounds.java
 * </p>
 * @author  Brendan O'Huiginn
 * @author  Tadhg O'Sullivan, rogue
 * @author <a href="mailto:tadhg.osullivan@ucdconnect.ie">tadhg.osullivan@ucdconnect.ie</a>
 * @version 1.0, 2007
 * @created 2-Mar-07 5:28:43 PM
 * @revised 
 * Copyright 2007 Brendan O'Huiginn
 * <p>
 * Description: methods for playing various sound files
 * </p>
 *  
 *  This file is part of Retribution.
 *
 *  Retribution is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Retribution is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Retribution; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *   
 *****************************************************************************/


public class GameSounds{
	Sequencer sequencer = null;
	Sequencer sequencer2 = null;
	//main theme
	public void MainTheme(){
		try {
			sequencer = MidiSystem.getSequencer();
		} catch (MidiUnavailableException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		if (sequencer == null) {
			System.out.println("sequencer not supported");

		} else {
			// Get resources
			try {
				sequencer.open();
			} catch (MidiUnavailableException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//load file into sequencer for playing
		try {
			//File myMidiFile = new File("theme.mid");
			URL myMidiFile = this.getClass().getResource("theme.mid");
			Sequence mySeq = MidiSystem.getSequence(myMidiFile);
			sequencer.setSequence(mySeq);
			sequencer.start();
			sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
		} catch (Exception e) {

		}
	}
	
	public void scaryTheme(){
		try {
			sequencer = MidiSystem.getSequencer();
		} catch (MidiUnavailableException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		if (sequencer == null) {
			System.out.println("sequencer not supported");

		} else {
			// Get resources
			try {
				sequencer.open();
			} catch (MidiUnavailableException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//load file into sequencer for playing
		try {
			//File myMidiFile = new File("ghostbusters.mid");
			URL myMidiFile = this.getClass().getResource("ghostbusters.mid");
			Sequence mySeq = MidiSystem.getSequence(myMidiFile);
			sequencer.setSequence(mySeq);
			sequencer.start();
			sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
		} catch (Exception e) {

		}
	}
	
	public void main2Theme(){
		try {
			sequencer = MidiSystem.getSequencer();
		} catch (MidiUnavailableException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		if (sequencer == null) {
			System.out.println("sequencer not supported");

		} else {
			// Get resources
			try {
				sequencer.open();
			} catch (MidiUnavailableException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//load file into sequencer for playing
		try {
			//File myMidiFile = new File("Pokemon.mid");
			URL myMidiFile = this.getClass().getResource("Pokemon.mid");
			Sequence mySeq = MidiSystem.getSequence(myMidiFile);
			sequencer.setSequence(mySeq);
			sequencer.start();
			sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
		} catch (Exception e) {

		}
	}
	
	public void main3Theme(){
		try {
			sequencer = MidiSystem.getSequencer();
		} catch (MidiUnavailableException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		if (sequencer == null) {
			System.out.println("sequencer not supported");

		} else {
			// Get resources
			try {
				sequencer.open();
			} catch (MidiUnavailableException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//load file into sequencer for playing
		try {
			//File myMidiFile = new File("cheers.mid");
			URL myMidiFile = this.getClass().getResource("cheers.mid");
			Sequence mySeq = MidiSystem.getSequence(myMidiFile);
			sequencer.setSequence(mySeq);
			sequencer.start();
			sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
		} catch (Exception e) {

		}
	}
	
	public void creditTheme(){
		try {
			sequencer = MidiSystem.getSequencer();
		} catch (MidiUnavailableException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		if (sequencer == null) {
			System.out.println("sequencer not supported");

		} else {
			// Get resources
			try {
				sequencer.open();
			} catch (MidiUnavailableException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//load file into sequencer for playing
		try {
			//File myMidiFile = new File("starwars.mid");
			URL myMidiFile = this.getClass().getResource("starwars.mid");
			Sequence mySeq = MidiSystem.getSequence(myMidiFile);
			sequencer.setSequence(mySeq);
			sequencer.start();
		} catch (Exception e) {

		}
	}
	
	public void splashTheme(){
		try {
			sequencer = MidiSystem.getSequencer();
		} catch (MidiUnavailableException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		if (sequencer == null) {
			System.out.println("sequencer not supported");

		} else {
			// Get resources
			try {
				sequencer.open();
			} catch (MidiUnavailableException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//load file into sequencer for playing
		try {
			//File myMidiFile = new File("sfx.mid");
			URL myMidiFile = this.getClass().getResource("sfx.mid");
			Sequence mySeq = MidiSystem.getSequence(myMidiFile);
			sequencer.setSequence(mySeq);
			sequencer.start();
			sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
		} catch (Exception e) {

		}
	}
	
	public void HauntedTheme(){
		try {
			sequencer2 = MidiSystem.getSequencer();
		} catch (MidiUnavailableException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		if (sequencer2 == null) {
			System.out.println("sequencer not supported");

		} else {
			// Get resources
			try {
				sequencer2.open();
			} catch (MidiUnavailableException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//load file into sequencer for playing
		try {
			//File myMidiFile = new File("haunted.mid");
			URL myMidiFile = this.getClass().getResource("haunted.mid");
			Sequence mySeq = MidiSystem.getSequence(myMidiFile);
			sequencer2.setSequence(mySeq);
			sequencer2.start();
			sequencer2.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
		} catch (Exception e) {
				System.out.println("poop");
		}
	}

	//Swords hitting
	public void SwordHit() throws FileNotFoundException{
		//Open an input stream  to the audio file.
		URL in = this.getClass().getResource("Sword1.wav");	
		//Create an AudioStream object from the input stream.
        AudioStream as = null;
		try {
			as = new AudioStream(in.openStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}         
       
        AudioPlayer.player.start(as);  
	}
	
	public void HeroSwordHit() throws FileNotFoundException{
		//Open an input stream  to the audio file.
		URL in = this.getClass().getResource("swordraw.wav");	
		//Create an AudioStream object from the input stream.
        AudioStream as = null;
		try {
			as = new AudioStream(in.openStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}         
       
        AudioPlayer.player.start(as);  
	}
	
	//Closing door
	public void DoorClose() throws FileNotFoundException{
//		Open an input stream  to the audio file.
		URL in = this.getClass().getResource("doorclose.wav");	
		//Create an AudioStream object from the input stream.
        AudioStream as = null;
		try {
			as = new AudioStream(in.openStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}         
       
        AudioPlayer.player.start(as);  
	}
	
	public void DoorCreak() throws FileNotFoundException{
//		Open an input stream  to the audio file.
		URL in = this.getClass().getResource("door_creak_1.wav");	
		//Create an AudioStream object from the input stream.
        AudioStream as = null;
		try {
			as = new AudioStream(in.openStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}         
       
        AudioPlayer.player.start(as);  
	}
	
	public void Punch() throws FileNotFoundException{
//		Open an input stream  to the audio file.
		URL in = this.getClass().getResource("punch.wav");	
		//Create an AudioStream object from the input stream.
        AudioStream as = null;
		try {
			as = new AudioStream(in.openStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}         
       
        AudioPlayer.player.start(as);  
	}
	
	public void EvilLaugh() throws FileNotFoundException{
//		Open an input stream  to the audio file.
		URL in = this.getClass().getResource("evil_laugh.wav");	
		//Create an AudioStream object from the input stream.
        AudioStream as = null;
		try {
			as = new AudioStream(in.openStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}         
       
        AudioPlayer.player.start(as);  
	}

	public void Grunt() throws FileNotFoundException{
	//	Open an input stream  to the audio file.
		URL in = this.getClass().getResource("urghhh.wav");	
		//Create an AudioStream object from the input stream.
	    AudioStream as = null;
		try {
			as = new AudioStream(in.openStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}         
	   
	    AudioPlayer.player.start(as);  
	}
	
	public void Coins() throws FileNotFoundException{
		//	Open an input stream  to the audio file.
			URL in = this.getClass().getResource("coin_1.wav");	
			//Create an AudioStream object from the input stream.
		    AudioStream as = null;
			try {
				as = new AudioStream(in.openStream());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}         
		   
		    AudioPlayer.player.start(as);  
		}
}
